home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / nospace.zip / NOSPACE.PAS < prev   
Pascal/Delphi Source File  |  1993-01-04  |  4KB  |  117 lines

  1. PROGRAM NoSpace;  {$L+,D+,E-,I+,S-,M 2000,0,2000}
  2. uses DOS, Crt, Mytools;
  3.  
  4. VAR
  5.   drive        : word;
  6.   BytesToCheck : longint;    {Variable integer for Disk Space}
  7.   MBytesFreeStr: string[30]; {String form of avail. disk space}
  8.   Err          : integer;
  9.   StrDrive     : string[1];
  10.   ParsedParam  : string[1];
  11.   pause        : char;
  12.  
  13. PROCEDURE DispErrs;
  14. begin
  15.   IF ParamCount = 0 THEN ClrScr;
  16.   Writeln;
  17.   Writeln;
  18.   Writeln('This program warns the user when a disk drive of his own selection');
  19.   Writeln('becomes nearly full.  The syntax is: Nospace <drive> <bytes for warning msg>');
  20.   Writeln('If no parameters are passed on the command line, then you see this message.');
  21.   Writeln('Syntax is: nospace <drive> <bytes> where <drive> = drive to check and');
  22.   Writeln('<bytes> = free bytes for the warning message.');
  23.   Writeln;
  24.   Writeln('Example in autoexec.bat file: nospace c: 2000000');
  25.   Writeln;
  26.   Writeln('This program has been put into the public domain and may not be sold.  It may');
  27.   Writeln('be copied freely and distributed where it may serve some use.  The author is');
  28.   Writeln('Larry Williams and I intend no further updates at this time.');
  29.   IF ParamCount = 0 THEN Halt(100);
  30. end;
  31.  
  32. PROCEDURE DispErrs1;
  33. begin
  34.   ClrScr;
  35.   Write(Chr(7));
  36.   Writeln;
  37.   AWrite(2,1,112,'ERROR: You must enter TWO parameters.  Please see below.                     ');
  38.   Disperrs;
  39.   Halt(99);
  40. end;
  41.  
  42. PROCEDURE DispErrs2;
  43. begin
  44.   ClrScr;
  45.   Write(Chr(7));
  46.   AWrite(2,1,112,'ERROR: The valid options for drives are:  A - Z                              ');
  47.   Disperrs;
  48.   Halt(98);
  49. end;
  50.  
  51. PROCEDURE DispErrs3;
  52. begin
  53.   ClrScr;
  54.   Write(Chr(7));
  55.   Writeln;
  56.   AWrite(2,1,112,'ERROR: You cannot enter more than two parameters, see below.                  ');
  57.   Disperrs;
  58.   Halt(97);
  59. end;
  60.  
  61. PROCEDURE IllegalDrive;
  62. {presently only works if the colon is put after the illegal drive letter}
  63. {need to parse the parameter to only one char}
  64. begin
  65.   TextAttr := 7; {makes sure standard video is displayed - gray on black}
  66.   ClrScr;
  67.   Write(Chr(7));
  68.   ABox(4,22,3,35,112,112,Border6,True);
  69.   AWriteC(5,112,'Drive ' + StrDrive + ' is an Unknown Drive');
  70.   Delay(1500);
  71.   Halt(0);
  72. end;
  73.  
  74.  
  75. PROCEDURE GoFigure; {Procedure to calculate if avail disk space ok}
  76. var
  77.   tempdrive : byte;
  78.   tempchar  : char;
  79.  
  80. begin
  81.   IF ParamCount = 2 THEN VAL(ParamStr(2),BytesToCheck,Err);
  82.   {If 2 params, evaluate which is larger}
  83.   StrDrive := UCase(ParamStr(1));  {Return uppercase Drive letter as string}
  84.   tempdrive := ord(StrDrive[1]);   {get ASCII Val of uppcase letter}
  85. {  ParsedParam := first char of StrDrive;}
  86.   Drive := ord(tempdrive) - 64;   {evaluate whether it is A-Z (1-26)}
  87.   IF ((Drive > 26) OR (Drive < 1)) THEN DispErrs2;
  88. end;
  89.  
  90.  
  91. {+++++++++ MAIN PROGRAM LOOP +++++++++++++++++++++++++++++++++++++++++++}
  92. BEGIN
  93.   IF ParamCount = 0 THEN DispErrs ELSE
  94.     IF ParamCount = 1 THEN DispErrs1 ELSE
  95.       IF ParamCount = 2 THEN GoFigure;
  96.       IF ParamCount > 2 THEN DispErrs3;
  97.       IF DiskFree(drive) < 0 THEN IllegalDrive; {check for invalid drive}
  98.  
  99.       {if bytes avail > specified no. of bytes, do nothing}
  100.       IF DiskFree(drive) > BytesToCheck THEN HALT(0);
  101.  
  102.       TextAttr := 7;
  103.       ClrScr;
  104.       Write(Chr(7));
  105.       ABox(9,15,5,50,112,112,Border3,True);
  106.       AWriteC(10,112,'Warning: LOW DISK SPACE on Drive '+ StrDrive + ':');
  107.  
  108.       {Convert bytes avail to string}
  109.       {bytes avail divided by 1 meg = mbytes avail}
  110.       Str(DiskFree(drive)/1000000:3:1,MBytesFreeStr);
  111.  
  112.       AWriteC(12,112,('Free bytes available: '+MBytesFreeStr+' Megabytes'));
  113.  
  114.       GotoXY(1,1);
  115.       Delay(1500) {pause}
  116. END.
  117.